// JavaScript Document
var key="";

//更换验证码
function changeKey() {
	key="";
	//验证码产生的数组
	var k=new Array(
		"0","1","2","3","4","5","6","7","8","9",
		"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
		"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
	);
	for(var i=0;i<4;i++) {	//循环4次  
		var index=Math.floor(62*Math.random());	//得到4个随机数
		key+=k[index];		//拼接得到一个4位的验证码
	}
	document.getElementById("changeKey").text=key;	//将验证码在页面上显示
}

function checkInfo(){
	//获取账号
	var account=$("#account").val();
	//获取密码
	var pwd=$("#pwd").val();
	//获取验证码
	var inputkey=document.getElementById("key").value;
	if(account==null){
		alert("账号不能为空...");
		return;
	}
	if(pwd==null){
		alert("密码不能为空...");
		return;
	}
	if(inputkey.toUpperCase()!=key.toUpperCase()) {
		alert("验证码错误!");
		changeKey();
		return;
	}else{
		if($("input[name='id']:checked").val()==0){//管理员登录
			$.ajax({
			    url: "login/login_admin",    //请求的url地址
			    dataType: "json",   //返回格式为json
			    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
			    data: { "account": account,"pwd":pwd},    //参数值
			    type: "POST", 
			    success: function(data) {
			        if(data>=1){
			        	location.href="back/index.jsp?id=admin"
			        }else{
			        	alert("账户或密码错误...");
			        	return;
			        }
			    },
			    error: function() {
			        //请求出错处理
			    }
			});
		}else{//维护人员登录
			$.ajax({
			    url: "login/login_staff",    //请求的url地址
			    dataType: "json",   //返回格式为json
			    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
			    data: { "account": account,"pwd":pwd},    //参数值
			    type: "POST", 
			    success: function(data) {
			        if(data>=1){
			        	location.href="back/index.jsp?id=staff"
			        }else{
			        	alert("账户或密码错误...");
			        	return;
			        }
			    },
			});
		}
	}
	
	
}

window.onload=changeKey;